import os
import re

end = False
start = False
countEnd = 0
subChanel = []


def remove_chinese_characters(text):
    pattern = re.compile(r'[\u4e00-\u9fff]+')  # 匹配中文字符的正则表达式
    return pattern.sub('', text)


with open('flavorsConfig.gradle', 'r', encoding='utf-8') as f:
    for line in f:
        if end:
            break
        lineStrip = line.strip()
        if start:
            # print('start---------------------------')
            if re.search(r'\w+\s\{', lineStrip):
                sub = re.sub(r"[^\w+]", "", lineStrip)
                sub = remove_chinese_characters(sub)
                # print('start-----------------------sub1:' + sub)
                subChanel.append(sub)
                countEnd = 0
            if lineStrip == '}':
                countEnd += 1
            if countEnd == 2:
                end = True
        if lineStrip.startswith('productFlavors'):
            start = True
subChanel.sort()
print('全部渠道：' + str(len(subChanel)))

transOutputPath = "test_app/"
apkFileName = []
if os.path.exists(transOutputPath):
    for file in os.listdir(transOutputPath):
        tempFile = os.path.join(file)
        if tempFile.endswith('.apk'):
            apkFileName.append(re.split(r"\.", tempFile)[0])
# print(apkFileName)

build_success_channel = []
build_failed_channel = []
for temp_channel in subChanel:
    if temp_channel in apkFileName:
        build_success_channel.append(temp_channel)
    else:
        build_failed_channel.append(temp_channel)
print("成功渠道：" + str(len(build_success_channel)))
print('失败渠道：' + str(len(build_failed_channel)) + str(build_failed_channel))
